<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row :gutter="10">
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button slot="append" type="primary" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
    </el-card>
    <!-- 订单列表数据区域 -->
    <el-table :data="orderList" border stripe style="width: 100%">
      <el-table-column type="index" label='#'>
      </el-table-column>
      <el-table-column prop="order_number" label="订单编号">
      </el-table-column>
      <el-table-column prop="order_price" label="订单价格">
        <template v-slot='{row}'>
          {{row.order_price}}
        </template>
      </el-table-column>
      <el-table-column prop="pay_status" label="是否付款">
        <!-- 是否已付款 -->
        <template v-slot='{row}'>
          <el-tag type="success" v-if="row.pay_status==='1'">已付款</el-tag>
          <el-tag type="danger" v-else>未付款</el-tag>
        </template>
      </el-table-column>
      <!-- 是否发货 -->
      <el-table-column prop="is_send" label="是否发货">
        <template v-slot='{row}'>
          {{row.is_send}}
        </template>
      </el-table-column>
      <!-- 下单时间 -->
      <el-table-column prop="create_time" label="下单时间">
        <template v-slot='{row}'>
          {{row.create_time|dateFormat}}
        </template>
      </el-table-column>
      <!-- 操作 -->
      <el-table-column label="操作">
        <!-- 操作按钮 -->
        <el-tooltip effect="light" content="编辑" placement="top">
          <!-- 编辑按钮 -->
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="showAddressBox"></el-button>
        </el-tooltip>
        <el-tooltip effect="light" content="物流信息" placement="top">
          <!-- 物流信息按钮 -->
          <el-button type="success" size="mini" icon="el-icon-location" @click='showPropressBox'></el-button>
        </el-tooltip>
      </el-table-column>
    </el-table>
    <!-- 分页功能区域 -->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum" :page-sizes="[1,4, 6, 10, 15]" :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>
    <!-- 修改地址的对话框 -->
    <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="50%" @close="editArddressVisbaleClose">
      <el-form ref="editAddressFormRef" :model="editAddressForm" :rules="editAddressFormRules" label-width="100px">
        <!-- 省市区/县 -->
        <el-form-item label="省市区/县" prop="address1">
          <!-- 级联选择器 -->
          <el-cascader class="size" v-model="editAddressForm.address1" :options="cityData"
            :props="{ expandTrigger: 'hover' }" @change="handleChange">
          </el-cascader>
        </el-form-item>
        <!-- 详细地址 -->
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息框 -->
    <el-dialog title="物流信息" :visible.sync="showDialogPropressVisible" width="30%" :before-close="handlePropressClose">
      <!-- 物流时间线 -->
      <el-timeline :reverse="true">
        <!-- reverse="false/true"  倒序或者正序 -->
        <el-timeline-item v-for="(item, index) in proressInfo" :key="index" :timestamp="item.time">
          {{item.content}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showDialogPropressVisible = false">取 消</el-button>
        <el-button type="primary" @click="showDialogPropressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      // 物流信息数据
      proressInfo: [],
      // 控制物流信息框的显示与隐藏
      showDialogPropressVisible: false,
      editAddressForm: {
        address1: [],
        address2: ''
      },
      // 修改地址的表单的验证规则
      editAddressFormRules: {
        address1: [
          { required: true, message: '请选择省市区县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      // 城市信息数据
      cityData,

      // 控制修改地址的对话框显示与隐藏
      editDialogVisible: false,
      queryInfo: {
        query: '', // 查询参数
        pagenum: 1, // 当前的页码
        pagesize: 4 // 每页显示的数据条数
      },
      total: 0,
      // 订单数据列表
      orderList: []
    }
  },
  methods: {
    // 物流信息框
    async showPropressBox () {
      // 跨域
      const { data: res } = await this.$http.get('http://localhost:8080/api/express')
      if (res.meta.status !== 200) return this.$message.error('物流信息获取失败')
      this.$message.success('物流信息获取成功')
      console.log(res.data)
      this.proressInfo = res.data
      this.showDialogPropressVisible = true
      console.log(this.proressInfo)
    },
    // 关闭物流信息框后事件重置
    handlePropressClose () { },
    // 关闭修改地址对话框后重置
    editArddressVisbaleClose () {
      this.$refs.editAddressFormRef.resetFields()
    },
    handleChange () { },
    // 修改地址按钮
    showAddressBox () {
      this.editDialogVisible = true
    },
    // 每一页的新数据
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    // 刷新新页数
    handleCurrentChange (newPagenum) {
      this.queryInfo.pagenum = newPagenum
      this.getOrderList()
    },
    // 获取订单列表数据
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.$message.success('获取订单列表成功')
      console.log(res)
      this.orderList = res.data.goods
      this.total = res.data.total
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  async created () {
    this.getOrderList()
    // const res = await this.$http.get('http://localhost:8080//api/person')
    // const res2 = await this.$http.get('http://localhost:8080//get/person')
    // console.log(res)
    // console.log(res2)
  },
  mounted () { }
}
</script>

<style scoped lang='less'>
.size {
  width: 100%;
}
</style>
